package com.test.hibernate.n21both;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/9/18 18:39
 */
@Data
@NoArgsConstructor
public class Customer {
    private Integer customerId;
    private String customerName;
    /**
     * 1.声明集合类型时，需要使用接口类型，因为hibernate在获取集合类型的时候，返回的是hibernate内置的集合类型，而不是JavaSE一个标准的集合实现
     * 2.需要把集合进行初始化，可以防止发生空指针异常
     */
    private Set<Order> orders = new HashSet<>();

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Customer customer = (Customer) o;
        return Objects.equals(customerId, customer.customerId) &&
                Objects.equals(customerName, customer.customerName) &&
                Objects.equals(orders, customer.orders);
    }

    @Override
    public int hashCode() {
        return Objects.hash(customerId, customerName, orders);
    }
}
